import React from 'react';

import styles from './GoodsNav.css';
import {Link} from "react-router-dom";

const userPage={
  "index":{
    pathname:"/point-shopping/admin",
    state:{
      "bodyName":"index"
    }
  },
  "giftOrder":{
    pathname:"/point-shopping/admin",
    state:{
      "bodyName":"giftOrder"
    }
  },
  "addGift":{
    pathname:"/point-shopping/admin",
    state:{
      "bodyName":"addGift"
    }
  },
  "ruleList":{
    pathname:"/point-shopping/admin",
    state:{
      "bodyName":"ruleList"
    }
  },
  "ruleListAndOption":{
    pathname:"/point-shopping/admin",
    state:{
      "bodyName":"ruleListAndOption"
    }
  },
  "addRule":{
    pathname:"/point-shopping/admin",
    state:{
      "bodyName":"addRule"
    }
  },
  "message":{
    pathname:"/point-shopping/admin",
    state:{
      "bodyName":"message"
    }
  },
  "addPoint":{
    pathname:"/point-shopping/admin",
    state:{
      "bodyName":"addPoint"
    }
  },
  "pointList":{
    pathname:"/point-shopping/admin",
    state:{
      "bodyName":"pointList"
    }
  },
  "countPoint":{
    pathname:"/point-shopping/admin",
    state:{
      "bodyName":"countPoint"
    }
  },
  "clearPoints":{
    pathname:"/point-shopping/admin",
    state:{
      "bodyName":"clearPoints"
    }
  }
};

 function showGiftMenu(bodyName,role) {
   if (role == 'ROLE_CP_ADMIN' || role == 'ROLE_RP_ADMIN' ) {
     return (
       <li className={bodyName == 'index' ? [styles.nav_item, styles["nav_item-active"]].join(' ') : styles.nav_item}>
         <Link to={userPage.index}>礼品列表</Link>
       </li>
     );
   }
 }

function showGiftOrderMenu(bodyName,role) {
  if (role == 'ROLE_CP_ADMIN' || role == 'ROLE_RP_ADMIN' ) {
    return (
      <li className={bodyName == 'giftOrder' ? [styles.nav_item, styles["nav_item-active"]].join(' ') : styles.nav_item}>
        <Link to={userPage.giftOrder}>礼品订单列表</Link>
      </li>
    );
  }
}
function showGiftAddMenu(bodyName,role) {
  if (role == 'ROLE_CP_ADMIN' || role == 'ROLE_RP_ADMIN' ) {
    return (
      <li className={bodyName=='addGift'?[styles.nav_item,styles["nav_item-active"]].join(' '):styles.nav_item}>
        <Link to={userPage.addGift}>新增礼品</Link>
      </li>
    );
  }
}

function showRuleMenu(bodyName,role) {
  if (role == 'ROLE_RP_ADMIN') {
    return (
      <li className={bodyName=='ruleList'||bodyName==''?[styles.nav_item,styles["nav_item-active"]].join(' '):styles.nav_item}>
        <Link to={userPage.ruleList}>规则列表</Link>
      </li>

    );
  }
}
function showRuleAddMenu(bodyName,role) {
  if (role == 'ROLE_RP_ADMIN') {
    return (
      <li className={bodyName=='addRule'?[styles.nav_item,styles["nav_item-active"]].join(' '):styles.nav_item}>
        <Link to={userPage.addRule}>新增规则</Link>
      </li>
    );
  }
}

function showPointMenu(bodyName,role) {
  if (role == 'ROLE_RP_ADMIN') {
    return (
      <li className={bodyName=='pointList'?[styles.nav_item,styles["nav_item-active"]].join(' '):styles.nav_item}>
        <Link to={userPage.pointList}>积分列表</Link>
      </li>

    );
  }
}
function showPointAddMenu(bodyName,role) {
  if (role == 'ROLE_RP_ADMIN') {
    return (
      <li className={bodyName=='addPoint'?[styles.nav_item,styles["nav_item-active"]].join(' '):styles.nav_item}>
        <Link to={userPage.addPoint}>添加积分</Link>
      </li>

    );
  }
}

function showCountPointMenu(bodyName,role) {
  if (role == 'ROLE_RP_ADMIN') {
    return (
      <li className={bodyName=='countPoint'?[styles.nav_item,styles["nav_item-active"]].join(' '):styles.nav_item}>
        <Link to={userPage.countPoint}>统计积分</Link>
      </li>

    );
  }
}


function showAdminMenu(bodyName,role) {
  if (role == 'ROLE_ROOT') {
    return (
      <li className={bodyName=='adminList'||bodyName==''?[styles.nav_item,styles["nav_item-active"]].join(' '):styles.nav_item}>
        <Link to={userPage.message}>管理员列表</Link>
      </li>

    );
  }
}

function showAdminRule(bodyName,role) {
  if (role == 'ROLE_ROOT') {
    return (
      <li className={bodyName=='ruleListAndOption'?[styles.nav_item,styles["nav_item-active"]].join(' '):styles.nav_item}>
        <Link to={userPage.ruleListAndOption}>活动列表</Link>
      </li>

    );
  }
}

function showAdminClearPoints(bodyName,role) {
  if (role == 'ROLE_ROOT') {
    return (
      <li className={bodyName=='clearPoints'?[styles.nav_item,styles["nav_item-active"]].join(' '):styles.nav_item}>
        <Link to={userPage.clearPoints}>清除积分</Link>
      </li>

    );
  }
}

const GoodsNav = ({bodyName,role}) => {

  return (
    <div className={styles.user_sidebar}>
      <div className="sidebar_header">
      </div>
      <ul className={styles.sidebar_nav}>
        {showGiftMenu(bodyName,role)}
        {showGiftOrderMenu(bodyName,role)}
        {showGiftAddMenu(bodyName,role)}
        {showRuleMenu(bodyName,role)}
        {showRuleAddMenu(bodyName,role)}
        {showPointMenu(bodyName,role)}
        {showPointAddMenu(bodyName,role)}
        {showAdminMenu(bodyName,role)}
        {showAdminRule(bodyName,role)}
        {showCountPointMenu(bodyName,role)}
        {showAdminClearPoints(bodyName,role)}
       </ul>
    </div>
  );
}

export default GoodsNav
